package com.base.system.base.db.specifications;

import javax.persistence.criteria.*;

public class IsEmptySpecification<T> extends AbstractSpecification<T> {

    private static final long serialVersionUID = 2718187875256032837L;
    private final String property;

    public IsEmptySpecification(String property, JoinType joinType) {
        this.property = property;
        this.joinType = joinType;
    }

    @Override
    public Predicate toPredicate(Root<T> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
        From from = getFrom(property, root);
        String attr = getProperty(property);
        return cb.isEmpty(from.get(attr));
    }
}
